#!/usr/bin/env php
<?php
/**
 * Installer for Floe project
 */
$version = file_get_contents(dirname(__FILE__).'/VERSION');
echo "Installing Floe $version...\n\n";

// create app skeleton
shell_exec("mkdir app; mkdir app/controllers; mkdir app/models; mkdir app/templates");

// create dev skeleton
shell_exec("mkdir dev; mkdir dev/config; mkdir dev/fixtures; mkdir dev/migrations; mkdir dev/tasks; mkdir dev/tests");

// create scratch folders
shell_exec("mkdir tmp; mkdir tmp/cache");

// create library and install application
shell_exec("mkdir lib; mv floe lib/floe; mv lib/floe/TaskRunner floe; mkdir web");

$index = "<?php\n
\n	require_once 'config.php';
\n	require_once LIB_DIR .'floe/server/Membrane.class.php';
\n	require_once LIB_DIR .'floe/server/receptors/IdentityDispatcher.class.php';
\n	require_once CTR_DIR.'application.controller.php';
\n
\n	\$server = new Membrane();
\n	\$server->attach(new IdentityDispatcher);
\n	\$server->run();
\n	?>";

file_put_contents('index.php', $index);

$config = "<?php\n
\n	define('WEB_HOST', 'http://mysite.local');
\n
\n	define('APP_DIR', dirname(__FILE__).\"/../app/\");
\n	define('DEV_DIR', dirname(__FILE__).\"/../dev/\");
\n	define('LIB_DIR', dirname(__FILE__).\"/../lib/\");
\n	define('TMP_DIR', dirname(__FILE__).\"/../tmp/\");
\n	define('CTR_DIR', dirname(__FILE__).\"/../app/controllers/\");
\n	define('TPL_DIR', dirname(__FILE__).\"/../app/templates/\");
\n	define('MOD_DIR', dirname(__FILE__).\"/../app/models/\");
\n	define('WEB_DIR', dirname(__FILE__));
\n
\n	define('DB_HOST', 'localhost');
\n	define('DB_NAME', 'database');
\n	define('DB_USER', 'username');
\n	define('DB_PASS', 'password');
\n
\n	require_once LIB_DIR .'floe/framework/Package.class.php';
\n
\n	define('MOMENT', date('Y-n-d H:i:s', mktime()));";

file_put_contents('index.php', $index);

?>